<?php

	function get_comments($itemID, $type = "product")
	{
		global $connection;
		
		if($type == "article")
		{
			$table = "articles_comments";
			$fieldName = "article_id";
		}
		elseif($type == "product")
		{
			$table = "products_comments";
			$fieldName = "product_id";
		}
		else
		{
			return false;
		}
		
		$query = "SELECT c.* FROM comments c
						LEFT JOIN {$table} cd ON cd.comment_id = c.id
								WHERE cd.{$fieldName} = ? AND c.language_id = ? AND c.visible = 1 ORDER BY c.date DESC";
		
		$comments = $connection->fetch_result($query, array($itemID, $_SESSION["language"]["id"]));
		return $comments;
	}
	
	function get_questions($productID)
	{
		global $connection;
		
			$table = "";
			$fieldName = "";
		
		$query = "SELECT pq.* FROM products_questions pq
								WHERE pq.product_id = ? AND pq.language_id = ? AND pq.answer != '' ORDER BY pq.date DESC";
		
		$comments = $connection->fetch_result($query, array($productID, $_SESSION["language"]["id"]));
		return $comments;
	}
?>